import { defineStore } from 'pinia'
import request from '@/utils/request'
import { ApiRes, BannerItem, BrandItem, HotItem, NewItem, ProductItem, SpecialItem } from '@/types/data'

export default defineStore('home', {
  state() {
    return {
      bannerList: [] as BannerItem[],
      newList: [] as NewItem[],
      hotList: [] as HotItem[],
      brandList: [] as BrandItem[],
      productList: [] as ProductItem[],
      specialList: [] as SpecialItem[],
    }
  },
  actions: {
    async getBannerList() {
      const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
      // console.log(res)
      this.bannerList = res.data.result
    },
    async getNewList() {
      const res = await request.get<ApiRes<NewItem[]>>('/home/new')
      // console.log(res)
      this.newList = res.data.result
    },
    async getHotList() {
      const res = await request.get<ApiRes<HotItem[]>>('/home/hot')
      // console.log(res)
      this.hotList = res.data.result
    },
    async getBrandList() {
      const res = await request.get<ApiRes<BrandItem[]>>('/home/brand')
      // console.log(res)
      // this.brandList = [...res.data.result, ...res.data.result]
      this.brandList = res.data.result
    },
    async getProductList() {
      const res = await request.get<ApiRes<ProductItem[]>>('/home/goods')
      // console.log(res)
      this.productList = res.data.result
    },
    async getSpecialList() {
      const res = await request.get<ApiRes<SpecialItem[]>>('/home/special')
      // console.log(res)
      this.specialList = res.data.result
    },
  }
})
